package net.yienyien.process.bpmn2bpel.test;

import java.io.IOException;

import net.yienyien.process.bpd.BPDModel;
import net.yienyien.process.bpd.BpdPackage;
import net.yienyien.process.bpd.transducer.ProviderException;
import net.yienyien.process.dfm.DfmPackage;
import net.yienyien.process.dfm4bpmn.Dfm4bpmnPackage;
import net.yienyien.process.pim.PimPackage;
import net.yienyien.process.pmm.PmmPackage;
import net.yienyien.process.pmm4bpmn.Pmm4bpmnPackage;
import net.yienyien.process2bpel.bpmn2bpd.BPMN2BPD;
import net.yienyien.process.folder.BPDFolder;
import net.yienyien.process.folder.BPDFolderFactory;
import net.yienyien.process.folder.stdPatterns.StdPatternsFactory;


import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
import org.eclipse.stp.bpmn.BpmnDiagram;
import org.eclipse.stp.bpmn.BpmnPackage;
import org.eclipse.wst.wsdl.WSDLPackage;
import org.eclipse.wst.wsdl.binding.http.HTTPPackage;
import org.eclipse.wst.wsdl.binding.soap.SOAPPackage;
import org.open.oasis.docs.wsbpel._2._0.plnktype.PlnktypePackage;
import org.open.oasis.docs.wsbpel._2._0.process.abstract_.AbstractPackage;


public class BPDSer {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		PimPackage.eINSTANCE.eClass();
		PmmPackage.eINSTANCE.eClass();
		BpmnPackage.eINSTANCE.eClass();
		BpdPackage.eINSTANCE.eClass();
		WSDLPackage.eINSTANCE.eClass();
		SOAPPackage.eINSTANCE.eClass();
		HTTPPackage.eINSTANCE.eClass();
		Pmm4bpmnPackage.eINSTANCE.eClass();
		AbstractPackage.eINSTANCE.eClass();
		PlnktypePackage.eINSTANCE.eClass();
		Dfm4bpmnPackage.eINSTANCE.eClass();
		DfmPackage.eINSTANCE.eClass();
		
		ResourceSet set=new ResourceSetImpl();
		
		set.getResourceFactoryRegistry().getExtensionToFactoryMap().put("bpmn", new XMIResourceFactoryImpl());
		set.getResourceFactoryRegistry().getExtensionToFactoryMap().put("bpd", new XMIResourceFactoryImpl());
		
		URI bpmnURI=URI.createFileURI("tmp/complaint.bpmn");
		
		Resource bpmnR=set.getResource(bpmnURI, true);
		
		BPDModel bpd=null;
		try {
			bpd = (new BPMN2BPD()).getBPDmodel(((BpmnDiagram)bpmnR.getContents().get(0)).getPools().get(0));
		} catch (ProviderException e1) {
			e1.printStackTrace();
		}
		
		BPDFolder folder;
		folder = BPDFolderFactory.INSTANCE.newBPDFolder();
		folder.addPattern(StdPatternsFactory.eINSTANCE.createFlow());
		folder.addPattern(StdPatternsFactory.eINSTANCE.createPick());
		folder.addPattern(StdPatternsFactory.eINSTANCE.createSequence());
		folder.addPattern(StdPatternsFactory.eINSTANCE.createSwitch());
		folder.addPattern(StdPatternsFactory.eINSTANCE.createRepeat());
		folder.addPattern(StdPatternsFactory.eINSTANCE.createWhile());
		folder.addPattern(StdPatternsFactory.eINSTANCE.createRepeatWhile());
		folder.addPattern(StdPatternsFactory.eINSTANCE
				.createSynchronizingProcess());
		folder.addPattern(StdPatternsFactory.eINSTANCE.createOther());
		
		folder.loopFold(bpd);
		
		
		Resource out=set.createResource(URI.createFileURI("tmp/out/complaint.bpd"));
		
		out.getContents().add(bpd);
		
		try {
			out.save(null);
		} catch (IOException e) {

			e.printStackTrace();
		}
		
	}

}
